import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

public class Solution524_2 {

    public static void main(String args[]){
        Solution524_2 s = new Solution524_2();
        System.out.println(s.findLongestWord("aewfafwafjlwajflwajflwafj", Arrays.asList(new String[]{"awefawfwaf"})));
    }

    public String findLongestWord(String s, List<String> d) {
        Collections.sort(d);
        String ret = "";
        for(String ts : d){
            if(cal(s, ts)){
                ret = ret.length() < ts.length() ? ts : ret;
            }
        }
        return ret;
    }

    public boolean cal(String a, String b){
        int lena = 0;
        for(int i = 0 ; i < b.length() ;){
            while(lena < a.length() && a.charAt(lena) != b.charAt(i)){
                lena ++;
            }
            if(lena == a.length()){
                return false;
            }
            lena ++;
            i ++;
        }
        return true;
    }
}
